package org.rasterfun.language2.bool

import org.rasterfun.language2.num.{NumIf, NumThenElse}
import org.rasterfun.language2.{BoolKind, IfExpression, ThenElse, Expression}

/**
 * Represents a boolean expression.
 * 
 * Contains methods for generating new expressions combining this and some other expression.
 * 
 * @author Hans Haggstrom
 */
trait Bool extends Expression {

	def kind = BoolKind

  def and(e: Bool): Bool = And(this, e)
  def or(e: Bool): Bool = Or(this, e)
  def xor(e: Bool): Bool = Xor(this, e)
  def not: Bool = Not(this)

  def &&(e: Bool): Bool = and(e)
  def ||(e: Bool): Bool = or(e)
  def ^^(e: Bool): Bool = xor(e)
  def unary_! : Bool = not

	def ===(e: Bool): Bool = BoolEqual(this, e)
	def !==(e: Bool): Bool = BoolNotEqual(this, e)

  def ?(thenElse: NumThenElse) = NumIf(this, thenElse.then, thenElse.otherwise)
  def ?(thenElse: BoolThenElse) = BoolIf(this, thenElse.then, thenElse.otherwise)

  def otherwise(b: Bool) = BoolThenElse(this, b)

  def operation(op: String, other: Expression): Expression = op.trim.toLowerCase match {
    case "and" => and(other)
    case "or" => or(other)
    case "xor" => xor(other)
  }

}

